/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Models;

import java.sql.*;
import java.util.Vector;
import Beans.PhanQuyenNhom;

/**
 *
 * @author Venus
 */
public class PhanQuyenNhom_Model {

    public static PhanQuyenNhom[] convertToArray(Vector v) {
        int n = v.size();
        PhanQuyenNhom[] arr = new PhanQuyenNhom[n];
        for (int i = 0; i < n; i++) {
            arr[i] = (PhanQuyenNhom) v.get(i);
        }
        return arr;
    }

    public static PhanQuyenNhom[] DSNhomQuyen(int mannv) {
        Vector dsnq = new Vector();// biáº¿n dsnn lÆ°u danh sÃ¡ch ngÃ´n ngá»¯ hiá»‡n cÃ³.
        String query = "";
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            query = "Select * from phanquyennhom where MaNNV = " + mannv + " ";
            rss = stmt.executeQuery(query);
            //rss = ConnectionPool.Select(query);
            while (rss.next()) {
                PhanQuyenNhom pqn = new PhanQuyenNhom();
                pqn.setMaQuyen(rss.getInt(1));
                pqn.setMaNNV(rss.getInt(2));
                pqn.setTinhTrang(rss.getByte(3));
                dsnq.add(pqn);
            }
            stmt.close();
            rss.close();
            conn.close();
            return convertToArray(dsnq);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }
    
}
